<?php
    session_start();
    require("../inc/db.class.php");
    $first_name= mysql_escape_string($_POST['first-name']);
    $last_name = mysql_escape_string($_POST['last-name']);
    $username = $first_name." ".$last_name;
    $email = mysql_escape_string($_POST['email']);
    $password = md5(mysql_escape_string($_POST['password']));
    $name = mysql_escape_string($_POST['name']);
    $dt_tm = date("Y-m-d H:i:s");
    $dbo= new database();
    
    if(strlen($password)<6)
    {
        $error=1;
    }
    //first name checking
    if(strlen($first_name)==0 || $first_name=='First Name' )
    {
        $error=1;
    }
    //last name checking
    if(strlen($last_name)==0 || $last_name=='Last Name' )
    {
        $error=1;
    }
    if(!$error){
        $insertUser="insert into users (email, first_name, last_name, password, username) values('$email', '$first_name', '$last_name', '$password', '$username') ";
        if($dbo->query($insertUser)){
            $_SESSION['logged_in']=true;
            $_SESSION['user_role']=$column['user_role'];
            $_SESSION['username']=$first_name." ".$last_name;
            $_SESSION['first_name'] = $first_name;
            $_SESSION['last_name'] = $last_name;
            $_SESSION['email'] = $email;
            $_SESSION['allow_write'] = true;
            $_SESSION['usr_nmbr'] = mysql_insert_id();
            header("location: ../index.php");
        }
        else
            header("location: ../registration.php");
    }else{
        header("location: ../registration.php?error=1");
    }
        
?>